#pragma once

#include <boost/asio.hpp>
#include <tbb/pipeline.h>
#include <tbb/tick_count.h>


// Forward declaration
class WorkManager;


/// Pipeline filter which polls ioservice events
class PollFilter : public tbb::filter
{
public:
	/// Constructs a filter that uses specified dispatch manager
	PollFilter(boost::asio::io_service &ioService, WorkManager &manager, bool showStat = false);

	/// Executes the filter
	/*override*/ void *operator()(void *);

private:
	/// The io_service used to poll results of asynchronous operations
	boost::asio::io_service &_ioService;

	/// DispatchManager holding dispatch queues
	WorkManager &_manager;

	/// Shows whether the filter should display statistics
	bool _showStat;

	/// Number of skips of statistics printing
	size_t _skips;

	/// Time of statistics gathering launch
	tbb::tick_count _startTime;

	/// Number of events polled
	size_t _totalPolled;

	/// Time spent on waiting in run_one
	double _waitTime;

	/// Number of waits in run_one
	size_t _waits;
};
